package com.jxd.project.absence.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jxd.project.absence.dao.IAbsenceDao;
import com.jxd.project.absence.dto.AbsenceDto;
import com.jxd.project.absence.dto.QueryFormDto;
import com.jxd.project.absence.dto.UpdateAbsenceDto;
import com.jxd.project.absence.model.Absence;
import com.jxd.project.absence.service.IAbsenceService;
import net.sf.jsqlparser.expression.DateTimeLiteralExpression;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName AbsenceServiceImpl
 * @Description TODO
 * @Author 李杨
 * @Date 2025/10/8 15:50
 * @Version 1.0
 */
@Service
public class AbsenceServiceImpl extends ServiceImpl<IAbsenceDao, Absence> implements IAbsenceService {
    @Autowired
    private IAbsenceDao absenceDao;
    @Override
    public List<AbsenceDto> getAbsence(QueryFormDto queryFrom) {
        queryFrom.setPage(queryFrom.getPage()-1);
        return absenceDao.listAbsence(queryFrom);
    }


    @Override
    public Boolean updateAbsence(UpdateAbsenceDto updateAbsenceDto) {
        int id = updateAbsenceDto.getId();
        Absence absence = absenceDao.selectById( id);
        absence.setRealEndTime(updateAbsenceDto.getRealEndTime());
        absence.setRealDays(updateAbsenceDto.getRealDays());
        return absenceDao.updateById(absence) > 0;
    }

    @Override
    public Map<String, String> getOneById(int id) {
        return absenceDao.getOneById(id);
    }

    @Override
    public int getMyToDo(String userid) {
        return absenceDao.getMyToDo(userid);
    }
}
